package acwing.图;

import acwing.高精度.add;

import java.util.Arrays;
import java.util.LinkedList;
import java.util.Queue;
import java.util.Scanner;

/**
 * 有向图的拓扑序列
 *
 * @author yang
 * @date 2021/12/27
 */
public class 有向图的拓扑序列 {

    static int N = 100010;
    // 头结点
    static int[] h = new int[N];
    // 链表元素
    static int[] e = new int[N];
    // next节点
    static int[] ne = new int[N];
    // 入度
    static int[] to = new int[N];
    // top序列的数组
    static int[] top = new int[N];
    static Queue<Integer> q = new LinkedList<>();

    static int idx, n, count = 1;
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        Arrays.fill(h, -1);
        n = sc.nextInt();
        int m = sc.nextInt();
        while (m-- > 0) {
            int x = sc.nextInt();
            int y = sc.nextInt();
            add(x, y);
            // 入度+1
            to[y]++;
        }
        if (topSort()) {
            for (int i = 1; i <= n; i++) {
                System.out.print(top[i] + " ");
            }
        }
        else System.out.println("-1");
    }

    private static boolean topSort() {

        for (int i = 1; i <= n; i++) {
            // 把入度为0的点全加入队列
            if (to[i] == 0) q.add(i);
        }
        while (!q.isEmpty()) {
            int t = q.poll();
            top[count++] = t;
            for (int i = h[t]; i != -1; i = ne[i]) {
                int j = e[i];
                // 减去一点边
                if (--to[j] == 0) {
                    q.add(j);
                }
            }
        }
        return count >= n;
     }

    public static void add(int a, int b) {
        e[idx] = b;
        ne[idx] = h[a];
        h[a] = idx++;
    }
}
